package com.foucus.myfouces.Adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.foucus.myfouces.MVP.Model.SquareVideoResp;
import com.foucus.myfouces.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yf-06 on 2017/6/30.
 */

public class SquareTitleAdapter extends RecyclerView.Adapter<SquareTitleAdapter.ViewHolder> {


    private Context mContext;
    private List<SquareVideoResp.ResultBean.DataBean> squareVideoList;

    public SquareTitleAdapter(Context mContext, List<SquareVideoResp.ResultBean.DataBean> squareVideoList) {
        this.mContext = mContext;
        this.squareVideoList = squareVideoList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rcl_squae_title, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        holder.tv_item_square_name.setText(squareVideoList.get(position).getName());
        SquareVideoAdapter squareVideoAdapter = new SquareVideoAdapter(mContext, squareVideoList.get(position).getVideo());
        holder.rcv_item_square_video.setLayoutManager(new GridLayoutManager(mContext, 2));
        holder.rcv_item_square_video.setAdapter(squareVideoAdapter);
        holder.rly_item_square_title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("ssss", "squareVideoList==>" + squareVideoList.get(position).getName());
            }
        });
    }

    @Override
    public int getItemCount() {
        return squareVideoList.size();

    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_item_square_name)
        TextView tv_item_square_name;
        @Bind(R.id.rly_item_square_title)
        RelativeLayout rly_item_square_title;
        @Bind(R.id.rcv_item_square_video)
        RecyclerView rcv_item_square_video;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
